home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / LAYOUT.PAK / LAYOUT.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  135 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1993, 1995 by Borland International, All Rights Reserved
  4. //
  5. // Program Description:
  6. //  Interactive program to demonstrate TLayout window.  It creates
  7. //  a frame window, colored child windows and a client window.
  8. //
  9. //  The menu choice lets you bring up a dialog to let you set values for a
  10. //  TLayoutMetrics structure for the various child windows (the dialog is
  11. //  modeless, so you can layout several windows at the same time).
  12. //  A TLayoutMetrics (declared in layoutwi.h) has four TLayoutConstraints
  13. //  in it, X, Y, Width and Height.  When the dialog comes up, you choose
  14. //  which constraint you want to select, then set the various members of
  15. //  that constraint.
  16. //  There are some constraints that you don't do with layout windows.
  17. //  For example, if you constrain the lmWidth edges of a X constraint, it
  18. //  will cause a error.  (The lmWidth edge is best constrained through the
  19. //  Width constraint).
  20. //
  21. //  Functionality Demonstrated:
  22. //   OWL:  Low level use of TLayoutWindow and TLayoutMetrics
  23. //----------------------------------------------------------------------------
  24. #include <owl/pch.h>
  25. #include <owl/framewin.h>
  26. #include <owl/applicat.h>
  27. #include <owl/layoutwi.h>
  28. #include "layout.rh"
  29. #include "layout.h"
  30. #include "laydia.h"
  31.  
  32. TMyChildWindow::TMyChildWindow(TWindow* parent, int id, char far* title,
  33.                                TColor color)
  34. :
  35.   TWindow(parent, title)
  36. {
  37.   SetBkgndColor(color);
  38.   Attr.Style = WS_CHILD | WS_BORDER | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS;
  39.   Attr.Id = id;
  40.   static int i = 0;
  41.   Attr.X = 10 + i++ * 100;
  42.   Attr.Y = 10;
  43.   Attr.W = 100;
  44.   Attr.H = 100;
  45. }
  46.  
  47. //----------------------------------------------------------------------------
  48.  
  49. DEFINE_RESPONSE_TABLE1(TMyLayout, TLayoutWindow)
  50.   EV_COMMAND(CM_LAYOUT, CmLayout),
  51.   EV_COMMAND(CM_RELAYOUT, CmReLayout),
  52. END_RESPONSE_TABLE;
  53.  
  54. TMyLayout::TMyLayout(TWindow* parent)
  55. :
  56.   TLayoutWindow(parent, 0)
  57. {
  58.   Attr.Style |= WS_BORDER;
  59.  
  60.   static TColor ChildColor[] = {
  61.     RGB(0xFF, 0x00, 0x00),
  62.     RGB(0x00, 0xFF, 0x00),
  63.     RGB(0x00, 0x00, 0xFF),
  64.     RGB(0xFF, 0xFF, 0x00),
  65.     RGB(0x00, 0xFF, 0xFF),
  66.     RGB(0xFF, 0x00, 0xFF),
  67.   };
  68.   static char* ChildName[] = {
  69.     "Red",
  70.     "Green",
  71.     "Blue",
  72.     "Yellow",
  73.     "Cyan",
  74.     "Magenta",
  75.   };
  76.  
  77.   int i = 0;
  78.   for (; i < MaxChildren; i++)
  79.     ChildInfo[i].Child = new TMyChildWindow(this, i+1, ChildName[i], ChildColor[i]);
  80.   ChildInfo[i].Child = 0;
  81.  
  82.   LayoutDialog = new TLayoutDialog(this, "IDD_LAYOUT", ChildInfo);
  83.  
  84. }
  85.  
  86. void
  87. TMyLayout::CmLayout()
  88. {
  89.   // Only one layout dialog at a time please
  90.   //
  91.   if (!LayoutDialog->GetHandle())
  92.     LayoutDialog->Create();
  93. }
  94.  
  95. //
  96. // Re-layout all of the children. Not really needed
  97. //
  98. void
  99. TMyLayout::CmReLayout()
  100. {
  101.   for (int i = 0; i < MaxChildren; i++)
  102.     SetChildLayoutMetrics(*ChildInfo[i].Child, ChildInfo[i].LayoutMetrics);
  103.   try {
  104.     Layout();
  105.   }
  106.   catch (TXOwl& exception) {
  107.     MessageBox(exception.why().c_str(), "Exception");
  108.   }
  109. }
  110.  
  111. void
  112. TMyLayout::SetupWindow()
  113. {
  114.   TLayoutWindow::SetupWindow();
  115.   PostMessage(WM_COMMAND, CM_RELAYOUT);
  116. }
  117.  
  118. //
  119. // class TLayoutApp
  120. // ~~~~~ ~~~~~~~~~~
  121. class TLayoutApp : public TApplication {
  122.   public:
  123.     void InitMainWindow() {
  124.       TFrameWindow* frame = new TFrameWindow(0, "Layout Window", new TMyLayout(0));
  125.       frame->AssignMenu(IDM_LAYOUT);
  126.       SetMainWindow(frame);
  127.     }
  128. };
  129.  
  130. int
  131. OwlMain(int, char**)
  132. {
  133.   return TLayoutApp().Run();
  134. }
  135.